<template>
  <div class="person">
    <h2>当前求和为：{{ sum }}</h2>
    <button @click="add">点我sum+1</button>
  </div>
</template>

<script setup lang="ts" name="Person">
  import { ref, onBeforeMount, onMounted, onBeforeUpdate, onUpdated, onBeforeUnmount, onUnmounted } from 'vue';

  //数据
  let sum = ref(0);
  //方法
  function add() {
    sum.value++;
  }

  //挂载前
  onBeforeMount(() => {
    console.log('onBeforeMount');
  })
  //挂载后
  onMounted(() => {
    console.log('onMounted');
  })
  //更新前
  onBeforeUpdate(() => {
    console.log('onBeforeUpdate');
  })
  //更新后
  onUpdated(() => {
    console.log('onUpdated');

  })
  //卸载前
  onBeforeUnmount(() => {
    console.log('onBeforeUnmount');
  })

  //卸载后
  onUnmounted(() => {
    console.log('onUnmounted');
  })


</script>
<style scoped>
  .person {
    width: 100%;
    background-color: skyblue;
    box-shadow: 0px 1px 2px #ddd;
    border-radius: 10px;
    padding: 20px;
  }

  button {
    margin: 0 5px;
  }

  li {
    font-size: 20px;
  }
</style>
